//
//  DocumentCell.m
//  StationManager
//
//  Created by 张佳强 on 17/3/15.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "DocumentCell.h"

@implementation DocumentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(unselected) name:@"unselected" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selected) name:@"selected" object:nil];
        
        self.selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.selectButton setImage:[UIImage imageNamed:@"unselected_bg"] forState:UIControlStateNormal];
        [self.selectButton setImage:[UIImage imageNamed:@"selected_bg"] forState:UIControlStateSelected];
        [self.selectButton addTarget:self action:@selector(selectClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.selectButton];
        
        self.documentLabel = [[UILabel alloc]init];
        self.documentLabel.font = [UIFont systemFontOfSize:13.0];
        [self.contentView addSubview:self.documentLabel];
        
        [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.top.equalTo(@0);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
        }];
        
        [self.documentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.selectButton.mas_right).offset(1);
            make.top.equalTo(@0);
            make.right.equalTo(@-5);
            make.height.mas_equalTo(30);
        }];
    }
    return self;
}

#pragma mark - Notification - Delegate

//当cell不选中时
- (void)unselected {
    
    self.selectButton.selected = NO;
    [self.documentDelegate removeAllDocuments];
}

//当cell选中时
- (void)selected {
    
    self.selectButton.selected = YES;
    [self.documentDelegate addAllDocuments];
}

//点击选择按钮
- (void)selectClick {
    
    if (self.selectButton.selected) {
        self.selectButton.selected = NO;
        [self.documentDelegate removeDocumentname:self.cellTag];

    }else{
        self.selectButton.selected = YES;
        [self.documentDelegate sendDocumentName:self.cellTag];

    }
}

//delegate方法的实现
- (void)sendDocumentName:(NSInteger)celltag {
    
}
- (void)removeDocumentname:(NSInteger)celltag {
    
}
- (void)removeAllDocuments {
    
}
- (void)addAllDocuments {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
